pullit together with storethat are the two workhorses of the finRes suite. Install the development version with devtools::install_github("bautheac/pullit").
Using carefully selected Bloomberg datafields from BBGsymbols in tandem with Armstrong, Eddelbuettel, and Laing (2018)’s Bloomberg interface pullit provides the R user with easy access to Bloomberg financial data for a collection of financial instruments that, at the time of writing, includes equity and equity-like securities, funds with the category encompassing any money-managing entity, as well as futures series & term structure individual contracts.
An active Bloomberg connection is required to retrieve Bloomberg financial data using pullit.
Equity data comes in three major categories in pullit, market, book and info. For a given corporation market data records stock market activity while book data records business activity in the form of financial statements commonly refered to as ‘books’ and info refers to qualitative information. See the ‘fields’ dataset in BBGsymbols for a detailed list of the Bloomberg fields available.
Retrieve market data from Bloomberg for Archer-Daniels-Midland (ADM US Equity), Kraft-Heinz (KHC US Equity) and XPO Logistics (XPO US Equity) with:
For financial statements data BBGsymbols replicates the Bloomberg ‘financial analysis’ monitor (FA
Retrieve the corresponding data for the abovementioned corporations with:
‘info’ encompasses a range of contemporaneous qualitative information including, but not limited to, firm’s name, security type, exchange where the security trades, country of incorporation, etc.
Retrieve the corresponding data for the abovementioned corporations with:
Fund data only comes in two categories, market and info. For a given fund market data records stock market activity while info data records contemporaneous qualitative information that includes a wide range of fund characteristics. Market historical data as well as contemporaneous qualitative data not only allow for an indepth assessment of the fund performance but potentially also the mapping of the performance to fund characteristics. See the ‘fields’ dataset in BBGsymbols for a detailed list of the Bloomberg datafields available.
Retrieve market data from Bloomberg for the SPDR S&P 500 ETF Trust (SPY US Equity), the SPDR Gold Shares investment fund (GLD US Equity) and the iShares MSCI Emerging Markets ETF (EEM US Equity) with:
Retrieve the corresponding qualitative data for the abovementioned funds with:
Futures data comes in three major categories in pullit, market, CFTC and info. For a given futures series market data records futures market price activity while CFTC data records market positions. ‘info’ on the other hand records contemporaneous qualitative information for the corresponding futures series, including but not limited to series name, term structure length, contract size, contract unit, etc. See the ‘fields’ dataset in BBGsymbols for a detailed list of the Bloomberg datafields available.
pullit helps retrieving both term structure as well as aggregated market data for futures. Term structure data records market activity for individual futures term structure contracts while aggregated data records market activity measures that are aggregated over the whole term structure for a particular futures series.
Retrieve market data from Bloomberg for the five first term structure contracts on the Corn - #2-yellow (C A Comdty), Eurodollar (EDA Comdty) and S&P500 - e-mini (ESA Index) futures series where the futures chains are constructed by rolling on liquidity (with active contract: “A”) with no roll adjustment (none: “N”) using:
Retrieve the corresponding aggregated futures market data with:
pullit helps retrieving CFTC futures market position data from Bloomberg. The Commodity Futures Trading Commission (CFTC) publishes the Commitments of Traders (COT) reports to help the public understand market dynamics. Specifically, the COT reports provide a breakdown of each Tuesday’s open interest for futures and options on futures markets in which 20 or more traders hold positions equal to or above the reporting levels established by the CFTC. See the ‘fields’ and ’’ datasets in BBGsymbols for a details.
Retrieve the corresponding futures market position data with:
‘info’ encompasses a range of contemporaneous qualitative information on the underlying futures series including, but not limited to, name for the series’ underlying, trading exchange, term structure length, contract size, etc.
Retrieve the corresponding data for the abovementioned futures series with:
The functions above return objects that not only carry the retrieved financial data but also complementary information that can be accessed using the @ operator or more formaly using bespoke accessor methods. Historical data functions for example return objects that carry a ‘tickers’ dataframe that indicates the tickers for which some data have been found, a ‘fields’ dataframe that indicates the data fields for which data has been found, a ‘data’ dataframe that hosts the retrieved data as well as a character vector hosting the original call to the function. A get_periods() method complements the accessor methods by indicating the start and end dates between which data have been found for each ticker and data field:
equity_market
#> S4 object of class EquityMarket
#>
#> Slots inlude
#> tickers: access with get_tickers()
#> fields: access with get_fields()
#> data: access with get_data()
#> call: access with get_call()
#>
#> See also: get_periods()Access each slot using the appropriate accessor:
get_fields(equity_market)
#> ticker instrument book symbol
#> 1: ADM US Equity equity market CUR_MKT_CAP
#> 2: ADM US Equity equity market EQY_SH_OUT
#> 3: ADM US Equity equity market PX_ASK
#> 4: ADM US Equity equity market PX_BID
#> 5: ADM US Equity equity market PX_HIGH
#> 6: ADM US Equity equity market PX_LAST
#> 7: ADM US Equity equity market PX_LOW
#> 8: ADM US Equity equity market PX_MID
#> 9: ADM US Equity equity market PX_OPEN
#> 10: ADM US Equity equity market PX_VOLUME
#> 11: KHC US Equity equity market CUR_MKT_CAP
#> 12: KHC US Equity equity market EQY_SH_OUT
#> 13: KHC US Equity equity market PX_ASK
#> 14: KHC US Equity equity market PX_BID
#> 15: KHC US Equity equity market PX_HIGH
#> 16: KHC US Equity equity market PX_LAST
#> 17: KHC US Equity equity market PX_LOW
#> 18: KHC US Equity equity market PX_MID
#> 19: KHC US Equity equity market PX_OPEN
#> 20: KHC US Equity equity market PX_VOLUME
#> 21: XPO US Equity equity market CUR_MKT_CAP
#> 22: XPO US Equity equity market EQY_SH_OUT
#> 23: XPO US Equity equity market PX_ASK
#> 24: XPO US Equity equity market PX_BID
#> 25: XPO US Equity equity market PX_HIGH
#> 26: XPO US Equity equity market PX_LAST
#> 27: XPO US Equity equity market PX_LOW
#> 28: XPO US Equity equity market PX_MID
#> 29: XPO US Equity equity market PX_OPEN
#> 30: XPO US Equity equity market PX_VOLUME
#> ticker instrument book symbolget_data(equity_market)
#> ticker field date value
#> 1: ADM US Equity CUR_MKT_CAP 2016-10-31 25347.4219
#> 2: ADM US Equity CUR_MKT_CAP 2016-11-01 26899.934
#> 3: ADM US Equity CUR_MKT_CAP 2016-11-02 27193.3878
#> 4: ADM US Equity CUR_MKT_CAP 2016-11-03 27291.2058
#> 5: ADM US Equity CUR_MKT_CAP 2016-11-04 26997.752
#> ---
#> 7976: XPO US Equity PX_VOLUME 2017-11-13 887972.0
#> 7977: XPO US Equity PX_VOLUME 2017-11-14 1221359.0
#> 7978: XPO US Equity PX_VOLUME 2017-11-15 2163577.0
#> 7979: XPO US Equity PX_VOLUME 2017-11-16 1205978.0
#> 7980: XPO US Equity PX_VOLUME 2017-11-17 1201417.0get_call(equity_market)
#> storethat_equity_market(tickers = equity_tickers, start = start,
#> end = end, file = "../data-raw/storethat.sqlite", verbose = FALSE)get_periods(equity_market)
#> ticker field start end
#> 1: ADM US Equity CUR_MKT_CAP 2016-10-31 2017-11-17
#> 2: ADM US Equity EQY_SH_OUT 2016-10-31 2017-11-17
#> 3: ADM US Equity PX_ASK 2016-10-31 2017-11-17
#> 4: ADM US Equity PX_BID 2016-10-31 2017-11-17
#> 5: ADM US Equity PX_HIGH 2016-10-31 2017-11-17
#> 6: ADM US Equity PX_LAST 2016-10-31 2017-11-17
#> 7: ADM US Equity PX_LOW 2016-10-31 2017-11-17
#> 8: ADM US Equity PX_MID 2016-10-31 2017-11-17
#> 9: ADM US Equity PX_OPEN 2016-10-31 2017-11-17
#> 10: ADM US Equity PX_VOLUME 2016-10-31 2017-11-17
#> 11: KHC US Equity CUR_MKT_CAP 2016-10-31 2017-11-17
#> 12: KHC US Equity EQY_SH_OUT 2016-10-31 2017-11-17
#> 13: KHC US Equity PX_ASK 2016-10-31 2017-11-17
#> 14: KHC US Equity PX_BID 2016-10-31 2017-11-17
#> 15: KHC US Equity PX_HIGH 2016-10-31 2017-11-17
#> 16: KHC US Equity PX_LAST 2016-10-31 2017-11-17
#> 17: KHC US Equity PX_LOW 2016-10-31 2017-11-17
#> 18: KHC US Equity PX_MID 2016-10-31 2017-11-17
#> 19: KHC US Equity PX_OPEN 2016-10-31 2017-11-17
#> 20: KHC US Equity PX_VOLUME 2016-10-31 2017-11-17
#> 21: XPO US Equity CUR_MKT_CAP 2016-10-31 2017-11-17
#> 22: XPO US Equity EQY_SH_OUT 2016-10-31 2017-11-17
#> 23: XPO US Equity PX_ASK 2016-10-31 2017-11-17
#> 24: XPO US Equity PX_BID 2016-10-31 2017-11-17
#> 25: XPO US Equity PX_HIGH 2016-10-31 2017-11-17
#> 26: XPO US Equity PX_LAST 2016-10-31 2017-11-17
#> 27: XPO US Equity PX_LOW 2016-10-31 2017-11-17
#> 28: XPO US Equity PX_MID 2016-10-31 2017-11-17
#> 29: XPO US Equity PX_OPEN 2016-10-31 2017-11-17
#> 30: XPO US Equity PX_VOLUME 2016-10-31 2017-11-17
#> ticker field start endAll the objects above can be stored in a bespoke database for later off-Bloomberg consumption. The storethat package makes the process seamless by providing befitted storing methods:
library(storethat)
db_create()
db_store(object = futures_TS, file = "~/storethat.sqlite", verbose = FALSE)
db_store(object = fund_market, file = "~/storethat.sqlite", verbose = FALSE)Every function above has an equivalent for retrieving data from a storethat database that can be accessed by swapping the ‘BBG’ prefix for ‘storethat’; i.e. ‘BBG_futures_market’ becomes ‘storethat_futures_market’. Function parameters are identical for both data sources and the returned objects have alike characteristics:
futures_TS <- storethat_futures_market(
type = "term structure", active_contract_tickers = futures_tickers,start, end,
TS_positions = 1L:5L, roll_type = "A", roll_days = 0L,
roll_months = 0L, roll_adjustment = "N", verbose = FALSE)
fund_market <- storethat_fund_market(fund_tickers, start, end, verbose = FALSE)Updating a storethat database is equally straightforward with pullit. Update the whole equity content of the database with:
More refined updates are also allowed:
The plotit package, also part of the finRes suite, provides plot methods for some pullit data objects including, at the time of writing, futures term structure (FuturesTS) and fund market (FundMarket) objects.
Plot a futures series term structure dynamics with:
Plot historical fund performance with:
Armstrong, Whit, Dirk Eddelbuettel, and John Laing. 2018. Rblpapi: R Interface to ’Bloomberg’. https://CRAN.R-project.org/package=Rblpapi.